//
//  CCEssenceViewController.m
//  BuDeJie
//
//  Created by demoncraz on 2017/2/9.
//  Copyright © 2017年 demoncraz. All rights reserved.
//

#import "CCEssenceViewController.h"
#import "CCAllViewController.h"
#import "CCVideoViewController.h"
#import "CCAudioViewController.h"
#import "CCPictureViewController.h"
#import "CCTextViewController.h"

@interface CCEssenceViewController ()

@property (nonatomic, weak) UIScrollView *scrollView;

@end

@implementation CCEssenceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor redColor];
    NSLog(@"%@", NSStringFromCGRect(self.view.frame));
    
    [self setupNavBar];
    self.automaticallyAdjustsScrollViewInsets = NO;
    //设置所有控制器
    [self setupAllChildViewControllers];
//    //设置滚动窗口
//    [self setupScrollView];
//    //设置顶部标题
//    [self setupTitleView];
    
    // Do any additional setup after loading the view.
}

- (void)setupAllChildViewControllers {
    
    CCAllViewController *allVc = [[CCAllViewController alloc] init];
    allVc.title = @"全部";
    CCVideoViewController *videoVc = [[CCVideoViewController alloc] init];
    videoVc.title = @"视频";
    CCAudioViewController *audioVc = [[CCAudioViewController alloc] init];
    audioVc.title = @"音频";
    CCPictureViewController *pictureVc = [[CCPictureViewController alloc] init];
    pictureVc.title = @"图片";
    CCTextViewController *textVc = [[CCTextViewController alloc] init];
    textVc.title = @"段子";
    
    [self addChildViewController:allVc];
    [self addChildViewController:videoVc];
    [self addChildViewController:audioVc];
    [self addChildViewController:pictureVc];
    [self addChildViewController:textVc];
    
}

- (void)setupScrollView {
    UIScrollView *scrollView = [[UIScrollView alloc] init];
    scrollView.frame = [UIScreen mainScreen].bounds;
    scrollView.backgroundColor = [UIColor greenColor];
    
    [self.view addSubview:scrollView];
    _scrollView = scrollView;
    scrollView.showsVerticalScrollIndicator = NO;
    scrollView.showsHorizontalScrollIndicator = NO;
    
}

- (void)setupTitleView {
    UIView *titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, CCScreenW, 35)];
    titleView.backgroundColor = [UIColor orangeColor];
    [self.view addSubview:titleView];
}

- (void)setupNavBar {
    
    //添加右上角barButtonItem

    self.navigationItem.rightBarButtonItem = [UIBarButtonItem barButtonItemWithImage:[UIImage imageOriginalWithName:@"navigationButtonRandomN_26x26_"] highImage:[UIImage imageOriginalWithName:@"navigationButtonRandomClick_26x26_"] target:self action:@selector(randomClick)];
    
    //添加titleView
    self.navigationItem.titleView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"MainTitle_107x19_"]];
    
}

- (UIBarButtonItem *)barButtonItemWithImage:(UIImage *)image highImage:(UIImage *)highImage target:(id)target action:(SEL)action {
    UIButton *barButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [barButton setImage:image forState:UIControlStateNormal];
    [barButton setImage:highImage forState:UIControlStateHighlighted];
    [barButton sizeToFit];
    UIView *containerView = [[UIView alloc] initWithFrame:barButton.bounds];
    [containerView addSubview:barButton];
    
    return [[UIBarButtonItem alloc] initWithCustomView:containerView];
}

- (void) randomClick {
    NSLog(@"%s",__func__);
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
